< previous page page_210 next page >

Page 210
MapPixel must map the output pixel location (ix_out, iy_out) back to the input location (x_in, y_in). Pixels are mapped from input locations to output locations using these formulas:
e10a6a0a59f035e870d90cca05b85fce.gif
x_out = (x_in - FromXmin) * XScale + ToXmin
y_out = (y_in - FromYmin) * YScale + ToYmin
Solving these equations for x_in and y_in gives the reverse mapping from output pixels back to input pixel locations.
e10a6a0a59f035e870d90cca05b85fce.gif
x_in = FromXmin + (ix_out - ToXmin) / XScale
y_in = FromYmin + (iy_out - ToYmin) / YScale
Subroutine MapPixel uses these inverse equations to find input pixel locations.
e10a6a0a59f035e870d90cca05b85fce.gif
' Copy the picture.
Private Sub EnlargePicture( _
    ByVal pic_from As PictureBox, _
    ByVal pic_to As PictureBox, _
    ByVal from_xmin As Single, ByVal from_ymin As Single, _
    ByVal from_wid As Single, ByVal from_hgt As Single, _
    ByVal to_xmin As Single, ByVal to_ymin As Single, _
    ByVal to_wid As Single, ByVal to_hgt As Single)

    ' Save mapping values.
    FromXmin = from_xmin
    FromYmin = from_ymin
    ToXmin = to_xmin
    ToYmin = to_ymin
    XScale = to_wid / (from_wid - 1)
    YScale = to_hgt / (from_hgt - 1)

    ' Transform the image.
    TransformImage pic_from, pic_to
End Sub

' Map the output pixel (ix_out, iy_out) to the input
' pixel (x_in, y_in).
Private Sub MapPixel( _
    ByVal ix_out As Single, ByVal iy_out As Single, _
    ByRef x_in As Single, ByRef y_in As Single)

    x_in = FromXmin + (ix_out - ToXmin) / XScale
    y_in = FromYmin + (iy_out - ToYmin) / YScale
End Sub
Taken together, subroutines EnlargePicture and MapPixel perform a task similar to the one performed by Visual Basic's PaintPicture method. They take the same parameters and produce a stretched image. EnlargePicture and MapPixel produce a smoother result.

 
< previous page page_210 next page >